package main

import (
	"fmt"
	"strings"
)

var name string = "John"
var age int = 30

func main() {
	eg1 := "hello world"
	eg2 := "hahaha"
	eg := eg1 + eg2
	fmt.Printf("My name is %s and I am %d years old.\n", name, age)
	fmt.Sprintf("%s%s", eg1, eg2)
	fmt.Printf("%s", eg)

	//分割
	ret := strings.Split(eg, " ")
	fmt.Println(ret)

	//判断是否包含
	fmt.Println(strings.Contains(eg, "world"))

	//判断前缀开头
	fmt.Println(strings.HasPrefix(eg, "hello"))
	//判断后缀结尾
	fmt.Println(strings.HasSuffix(eg, "world"))

	//索引
	fmt.Println(strings.Index(eg, "world"))
	fmt.Println(strings.LastIndex(eg, "world"))

	//替换
	fmt.Println(strings.Replace(eg, "world", "go", 1))

	//拼接
	fmt.Println(strings.Join(ret, " "))

	for _, v := range ret {
		fmt.Println(v)
	}
	s1 := "hello"
	s2 := []rune(s1) //将字符串转换为rune切片
	s2[0] = 'c'
	fmt.Println(string(s2)) //将rune切片转换回字符串

}
